package com.mephi.oshs.presenter;

import com.mephi.oshs.model.entry.IEntry;
import com.mephi.oshs.view.api.IExploreView;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class ExplorePresenter extends AbstractPresenter {

    @Override
    public void bind() {
        final IExploreView exploreView = this.getExploreView();
        exploreView.getSaveEditsAction().addClickListener(new Listener() {

            @Override
            public void handleEvent(Event event) {
                onSaveEdits();
            }
        });
    }

    @Override
    public void unbind() {
        throw new RuntimeException("unbind(): Not implemented yet.");
    }

    private void onSaveEdits() {
        final IEntry selectedEntry = super.getOshsPresenter().getSelectedEntry();
        if (selectedEntry != null) {
            selectedEntry.setShortName(this.getExploreView().getShortNameTextField().getText());
            selectedEntry.notifyObservers();
        }
    }
}
